﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true"
    CodeBehind="SAPPOSLineEdit.aspx.cs" Inherits="SapB1WebPOS.SAPPOSLineEdit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PopupContent" runat="server">
    <table style="width: 100%; font-family: Courier New;" border="0">
        <tr>
            <td>
                Item code
            </td>
            <td>
                Item Name
            </td>
            <td>
                UoM
            </td>
        </tr>
        <tr>
            <td>
                <span id="ItemCode" style="margin-left: 10px; font-weight: bold;">ItemCode</span>
            </td>
            <td>
                <span id="lblDscription" style="margin-left: 10px; font-weight: bold;">
                    <input type="text" name="Dscription" id="Dscription" class="k-textbox" style="width: 250px;" /></span>
            </td>
            <td>
                <span id="unitMsr" style="margin-left: 10px; font-weight: bold;">unitMsr</span>
            </td>
        </tr>
        <tr>
            <td>
                Warehouse
            </td>
            <td>
                Tax
            </td>
            <td>
                Sales Person
            </td>
        </tr>
        <tr>
            <td>
                <span id="Span1" style="margin-left: 10px; font-weight: bold;">
                    <input type="text" name="Warehouse" id="Warehouse" style="width: 250px;" />
            </td>
            <td>
                <span id="Span2" style="margin-left: 10px; font-weight: bold;">
                    <input type="text" name="Tax" id="Tax" style="width: 250px;" />
            </td>
            </span></td>
            <td>
                <span id="Span3" style="margin-left: 10px; font-weight: bold;">
                    <input type="text" name="SalesPerson" id="SalesPerson" style="width: 250px;" />
            </td>
            </span></td>
        </tr>
    </table>
    <br />
    <table style="width: 100%; font-family: Courier New; background-color: #283593; color: #fff;
        border-bottom-color: #fff" border="1">
        <tr>
            <td class="text-right">
                <div style="margin-right: 5px; font-family: Courier New;">
                    <b>Quantity</b></div>
            </td>
            <td class="text-right">
                <div style="margin-right: 5px; font-family: Courier New;">
                    <b>Price</b></div>
            </td>
            <td class="text-right">
                <div style="margin-right: 5px; font-family: Courier New;">
                    <b>Discount</b></div>
            </td>
        </tr>
        <tr>
            <td class="text-right">
                <input type="text" class="k-input k-textbox" name="Quantity" id="Quantity" required="required"
                    validationmessage="Pls input Quantity." style="width: 100%; text-align: right;
                    font-weight: bold; font-size: 14pt;" />
            </td>
            <td class="text-right">
                <input type="text" class="k-input k-textbox" name="PriceBefDi" id="PriceBefDi" required="required"
                    validationmessage="Pls input Price." style="width: 100%; text-align: right; font-weight: bold;
                    font-size: 14pt;" />
            </td>
            <td class="text-right">
                <input type="text" class="k-input k-textbox" name="DiscPrcnt" id="DiscPrcnt" required="required"
                    validationmessage="Pls input Discount." style="width: 100%; text-align: right;
                    font-weight: bold; font-size: 14pt;" />
            </td>
        </tr>
    </table>
    <br />
    <table style="width: 100%;">
        <tr>
            <td align="left">
                <span id="errMsg" class="fake" style="font-size: medium"></span>
            </td>
            <td align="right">
                <button type="button" id="btnAccept" class="k-button k-button-icontext k-primary"
                    style="width: 150px; height: 50px;" onclick="return btnAccept_onclick()">
                    <span class="k-icon k-update"></span>Accept</button>&nbsp;
                <button type="button" id="btnCancel" class="k-button k-button-icontext k-grid-cancel"
                    style="width: 150px; height: 50px;" onclick="return btnCancel_onclick()">
                    <span class="k-icon k-i-cancel"></span>Cancel</button>
            </td>
        </tr>
    </table>
    <script language="javascript" type="text/javascript">
        var lineNum;
        $(document).ready(function () {
            var warehouse = $("#Warehouse").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Warehouse]",
                dataTextField: "WhsName",
                dataValueField: "WhsCode",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "SAPPOSLineEdit.aspx/GetWarehouse",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        }
                    },
                    type: "odata",
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return JSON.parse(data);
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "WhsCode",
                            fields: {
                                WhsCode: { type: "string", validation: { required: true} },
                                WhsName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            var tax = $("#Tax").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Tax]",
                dataTextField: "Name",
                dataValueField: "Code",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "SAPPOSLineEdit.aspx/GetTax",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        }
                    },
                    type: "odata",
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return JSON.parse(data);
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "WhsCode",
                            fields: {
                                WhsCode: { type: "string", validation: { required: true} },
                                WhsName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            var SalesPerson = $("#SalesPerson").kendoDropDownList({
                filter: "contains",
                optionLabel: "[Select Sales Person]",
                dataTextField: "SlpName",
                dataValueField: "SlpCode",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "SAPPOSLineEdit.aspx/GetSalesPerson",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        }
                    },
                    type: "odata",
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return JSON.parse(data);
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "SlpCode",
                            fields: {
                                SlpCode: { type: "string", validation: { required: true} },
                                SlpName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            $("#Quantity").keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    btnAccept_onclick();
                }
            });
            $("#PriceBefDi").keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    btnAccept_onclick();
                }
            });
            $("#DiscPrcnt").keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    btnAccept_onclick();
                }
            });

            lineNum = '<%= Request.QueryString["LineNum"] %>';
            var itemCode = '<%= Request.QueryString["ItemCode"] %>';
            var itemName = '<%= Request.QueryString["Dscription"] %>';
            var uoM = '<%= Request.QueryString["unitMsr"] %>';
            var quantity = '<%= Request.QueryString["Quantity"] %>';
            var price = '<%= Request.QueryString["PriceBefDi"] %>';
            var discount = '<%= Request.QueryString["DiscPrcnt"] %>';
            var warehouse = '<%= Request.QueryString["WhsCode"] %>';
            var tax = '<%= Request.QueryString["VatGroup"] %>';
            var salesPerson = '<%= Request.QueryString["SlpCode"] %>';

            $("#ItemCode").text(itemCode);
            $("#Dscription").val(itemName);
            $("#unitMsr").text(uoM);
            $("#Quantity").val(quantity);
            $("#PriceBefDi").val(round2Fixed(price));
            $("#DiscPrcnt").val(discount);

            $("#Warehouse").data("kendoDropDownList").value(warehouse);
            $("#Tax").data("kendoDropDownList").value(tax);
            $("#SalesPerson").data("kendoDropDownList").value(salesPerson);


        });
        function btnAccept_onclick() {
            $("#errMsg").text('');
            var itemCode = $("#ItemCode").text();
            var quantity = $("#Quantity").val();
            if (quantity == "") {
                $("#errMsg").text('Please input Quantity');
                return;
            }
            var price = $("#PriceBefDi").val();
            if (price == "") {
                $("#errMsg").text('Please input Price.');
                return;
            }
            var discount = $("#DiscPrcnt").val();
            if (discount == "") {
                $("#errMsg").text('Please input Discount.');
                return;
            }
            var warehouse = $("#Warehouse").val();
            if (warehouse == "") {
                $("#errMsg").text('Please select Warehouse.');
                return;
            }
            var tax = $("#Tax").val();
            if (tax == "") {
                $("#errMsg").text('Please select Tax.');
                return;
            }
            var salesPerson = $("#SalesPerson").val();
            if (salesPerson == "") {
                $("#errMsg").text('Please select Sales Person.');
                return;
            }
            var dscription = $("#Dscription").val();
            if (dscription == "") {
                $("#errMsg").text('Please input Item Name.');
                return;
            }
            parent.UserUpdateLine(lineNum, itemCode, quantity, price, discount, warehouse, tax, salesPerson, dscription);
        }

        function btnCancel_onclick() {
            parent.$("#editLineItem").data("kendoWindow").close();
        }
    </script>
</asp:Content>
